﻿// Developer Express Code Central Example:
// World Wide CRM Demo
// 
// The World Wide CRM demo is a next generation application with outstanding
// navigation capabilities and shows a reimagined view of customer contact and
// management. This demo showcases many of the most popular features of the
// WinForms Subscription.
// 
// You can find sample updates and versions for different programming languages here:
// http://www.devexpress.com/example=E3993

using System;

namespace DevExpress.CrmDemo.Win.Helpers
{
    public static class EnumExtensions
    {
        public static TEnum ToEnum<TEnum>(this string text, TEnum defaultValue) where TEnum : struct 
        {
            foreach (string name in Enum.GetNames(typeof(TEnum)))
            {
                if (text == name)
                {
                    return (TEnum) (Enum.Parse(typeof (TEnum), text));
                }
            }
            return defaultValue;
        }
    }
}